import Main from '@/views/Main.vue'

// 不作为Main组件的子页面展示的页面单独写，如下
export const loginRouter = {
  path: '/login',
  name: 'login',
  component: resolve => {
    require(['@/views/Login.vue'], resolve)
  }
}

export const page404 = {
  path: '/*',
  name: 'error-404',
  meta: {
    title: '404-页面不存在'
  },
  component: resolve => {
    require(['@/views/error-page/404.vue'], resolve)
  }
}

export const page403 = {
  path: '/403',
  meta: {
    title: '403-权限不足'
  },
  name: 'error-403',
  component: resolve => {
    require(['@//views/error-page/403.vue'], resolve)
  }
}

export const page500 = {
  path: '/500',
  meta: {
    title: '500-服务端错误'
  },
  name: 'error-500',
  component: resolve => {
    require(['@/views/error-page/500.vue'], resolve)
  }
}

// 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherRouter里
export const otherRouter = {
  path: '/',
  component: resolve => require(['@/views/home/Main'], resolve),
  children: [{
    path: '',
    name: 'home',
    component: resolve => require(['@/views/home/Index'], resolve)
  }, {
    path: 'ranking/:type',
    name: 'ranking',
    component: resolve => require(['@/views/home/Ranking'], resolve)
  }, {
    path: '/logout',
    name: 'logout'
  }, {
    path: 'news',
    name: 'news',
    meta: {
      anonymous: true
    },
    component: resolve => require(['@/views/home/News'], resolve)
  }, {
    path: 'courses',
    name: 'courses',
    component: resolve => require(['@/views/home/Courses'], resolve)
  }, {
    path: 'courses/:id/:index?',
    name: 'course-detail',
    meta: {
      anonymous: true
    },
    component: resolve => require(['@/views/lessons/Detail'], resolve)
  }, {
    path: 'notes',
    name: 'notes',
    component: resolve => require(['@/views/home/Notes'], resolve)
  }, {
    path: 'lives',
    name: 'lives',
    component: resolve => require(['@/views/home/Lives'], resolve)
  }, {
    path: 'lives/:id',
    name: 'live-details',
    component: resolve => require(['@/views/home/LiveDetail'], resolve)
  }, {
    path: 'tags',
    name: 'tags',
    component: resolve => require(['@/views/home/Tags'], resolve)
  }, {
    path: 'search/:type',
    name: 'search',
    component: resolve => require(['@/views/home/Search'], resolve)
  }, {
    path: 'questions',
    name: 'questions',
    component: resolve => require(['@/views/home/Questions'], resolve)
  }, {
    path: 'questions/:id/:replyId?',
    name: 'question-detail',
    component: resolve => require(['@/views/questions/Detail'], resolve)
  }, {
    path: 'new-question',
    name: 'new-question',
    component: resolve => require(['@/views/questions/New'], resolve)
  }, {
    path: 'edit-question/:id',
    name: 'edit-question',
    component: resolve => require(['@/views/questions/New'], resolve)
  }, {
    path: 'manage',
    name: 'manage',
    component: resolve => require(['@/views/manage/Main'], resolve),
    redirect: '/manage/courses/created',
    children: [{
      path: 'notifications',
      name: 'notifications',
      component: resolve => require(['@/views/manage/Notifications'], resolve)
    }, {
      path: 'courses/:type',
      name: 'my-courses',
      component: resolve => require(['@/views/manage/Courses'], resolve)
    }, {
      path: 'new-course',
      name: 'manage-new-course',
      component: resolve => require(['@/views/lessons/New'], resolve)
    }, {
      path: 'edit-course/:id',
      name: 'manage-edit-course',
      component: resolve => require(['@/views/lessons/New'], resolve)
    }]
  }]
}

// 作为Main组件的子页面展示并且在左侧菜单显示的路由写在appRouter里
export const appRouter = [{
  path: 'lessons/new',
  title: '添加课程',
  hide: true,
  name: 'lessons_new',
  component: resolve => require(['@/views/lessons/New'], resolve)
}, {
  path: 'lessons/edit/:id',
  title: '编辑课程',
  hide: true,
  tagged: true,
  name: 'lessons_edit',
  component: resolve => require(['@/views/lessons/New'], resolve)
}, {
  path: 'lessons/:id/comments',
  title: '课程评论',
  hide: true,
  tagged: true,
  name: 'lessons_comments',
  component: resolve => require(['@/views/comments/Index'], resolve)
}, {
  path: 'index',
  icon: 'ios-home',
  title: '管理首页',
  name: 'dashboard',
  component: resolve => require(['@/views/admin/Dashboard'], resolve)
}, {
  path: 'lessons/index',
  icon: 'android-document',
  group: 'sidebar',
  tagged: true,
  title: '课程',
  name: 'admin-lessons',
  component: resolve => require(['@/views/admin/Lessons'], resolve)
}, {
  path: 'posts/index',
  icon: 'android-chat',
  tagged: true,
  title: '问答',
  name: 'admin-posts',
  component: resolve => require(['@/views/admin/Posts'], resolve)
}, {
  path: 'posts/:id/replies',
  icon: 'android-chat',
  hide: true,
  tagged: true,
  title: '管理回复',
  name: 'post-replies',
  component: resolve => require(['@/views/admin/PostReplies'], resolve)
}, {
  path: 'tags/index',
  icon: 'android-bookmark',
  title: '知识点',
  name: 'admin-tags',
  component: resolve => require(['@/views/admin/Tags'], resolve)
}, {
  path: 'lives/index',
  icon: 'android-camera',
  tagged: true,
  title: '直播',
  name: 'admin-lives',
  component: resolve => require(['@/views/admin/Lives'], resolve)
}, {
  path: 'lives/new',
  icon: 'android-camera',
  tagged: false,
  hide: true,
  title: '新增直播',
  name: 'new-live',
  component: resolve => require(['@/views/admin/NewLive'], resolve)
}, {
  path: 'lives/:id/edit',
  icon: 'android-camera',
  tagged: false,
  hide: true,
  title: '编辑直播',
  name: 'edit-live',
  component: resolve => require(['@/views/admin/NewLive'], resolve)
}]

// 所有上面定义的路由都要写在下面的routers里
export const routers = [
  loginRouter,
  otherRouter,
  {
    path: '/admin',
    title: '管理后台',
    name: 'admin',
    component: Main,
    children: appRouter,
    redirect: '/admin/index'
  },
  page500,
  page403,
  page404
]
